<?php

namespace frontend\modules\trade\models;

use Yii;
use common\models\trade\TradePaymode;

/**
 * 查询待支付订单信息
 * PaymentOrderSearch use to bizorder payment model.
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class PaymentOrderSearch extends BizOrderModel {

    /**
     * 待支付订单支付
     * @inheritdoc
     */
    public function save() {
        if (!$this->validate()) {
            return $this->dumpError('', $this->getFirstErrors());
        }
        $model = $this->getModel();
        $model->setPaying();
        if (!$model->save()) {
            return $this->dumpError($model->getErrorMsg());
        }
        $paymodes = TradePaymode::findAll([
            'deleted_at' => 0,
            'status' => TradePaymode::STATUS_ACTIVE,
        ]);
        return [
            'id' => $model->id,
            'order_no' => $model->order_no,
            'price' => $model->price,
            'countdown' => $model->countdown,
            'paymodes' => $paymodes
        ];
    }

}
